package com.fenghongzhang.a1807;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

public class MyDialog extends Dialog {
    private TextView title;
    private TextView message;
    private Button no;
    private Button yes;


    private static final String TAG = "MyDialog";
    private String strTitle;

    public String getStrTitle() {
        return strTitle;
    }

    public void setStrTitle(String strTitle) {
        this.strTitle = strTitle;
    }

    private String strMessage;

    public String getStrMessage() {
        return strMessage;
    }

    public void setStrMessage(String strMessage) {
        this.strMessage = strMessage;
    }

    public MyDialog(@NonNull Context context) {
        super(context);
    }

    //1,自定义一个接口
    public interface YesClickListener{
        void yesClick();
    }

    //2,声明一个成员
    private YesClickListener yesClickListener;

    //3,set和get方法
    public YesClickListener getYesClickListener() {
        return yesClickListener;
    }

    public void setYesClickListener(YesClickListener yesClickListener) {
        this.yesClickListener = yesClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);//R
        setContentView(R.layout.custom_layout);

        //外部不能取消
        setCanceledOnTouchOutside(false);

        title = (TextView) findViewById(R.id.title);
        message = (TextView) findViewById(R.id.message);
        no = (Button) findViewById(R.id.no);
        yes = (Button) findViewById(R.id.yes);


        if(strMessage != null){
            message.setText(strMessage); //

        }
        if(strTitle != null){
            title.setText(strTitle); //null
        }

        //点击事件
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "onClick:111 ");
                yesClickListener.yesClick();
                dismiss();
            }
        });

        //4
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                noClickListener.noClick();
                dismiss();
            }
        });
    }

    //1
    public interface NoClickListener{
        void noClick();
    }
    //2
    private NoClickListener noClickListener;

    //3
    public void setNoClickListener(NoClickListener noClickListener) {
        this.noClickListener = noClickListener;
    }
}
